package com.dream.springmvc.value;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author zhaoshichang
 */
@Data
@AllArgsConstructor
public class DatetimeValue implements Value<LocalDateTime> {
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    private LocalDateTime value;

    @JsonCreator
    public static DatetimeValue fromJson(String val) {
        return new DatetimeValue(LocalDateTime.parse(val, FORMATTER));
    }
}
